package org.kazao.sms;

import java.util.*;

public class KazaoMessage {
    public static final int MESSAGE_ENCODING_7BIT = 1;
    public static final int MESSAGE_ENCODING_8BIT = 2;
    public static final int MESSAGE_ENCODING_UNICODE = 3;
    
    public static final int TYPE_INCOMING = 1;
    public static final int TYPE_OUTGOING = 2;
    
    private int type;
    protected String id;
    protected int memIndex;
    protected Date date;
    protected String originator;
    protected String recipient;
    protected String text;
    protected int messageEncoding;
    protected boolean flash;
    protected boolean report;
    
    public KazaoMessage(int type, Date date, String originator, String recipient, String text, int memIndex, boolean flash, boolean report) {
        this.type = type;
        this.date = date;
        this.originator = originator;
        this.recipient = recipient;
        this.text = text;
        this.memIndex = memIndex;
        this.setFlash(flash);
        this.setReport(report);
        this.messageEncoding = MESSAGE_ENCODING_7BIT;
    }
    
    public int getType() {
        return type;
    }
    
    public String getId() {
        return id;
    }
    
    /**
     * Returns the memory index of the GSM device, where the message is stored.
     * Applicable only for incoming messages.
     *
     * @return  the memory index of the message.
     */
    public int getMemIndex() {
        return memIndex;
    }
    
    public Date getDate() {
        return date;
    }
    
    public String getText() {
        return text;
    }
    
    public String getHexText() {
        return KazaoGSMAlphabets.text2Hex(text, KazaoGSMAlphabets.GSM7BITDEFAULT);
    }
    
    public int getMessageEncoding() {
        return messageEncoding;
    }
    
    public void setId(String id) {
        this.id = id;
    }
    
    public void setText(String text) {
        this.text = text;
    }
    
    public void setDate(Date date) {
        this.date = date;
    }
    
    public void setMessageEncoding(int messageEncoding) {
        this.messageEncoding = messageEncoding;
    }
    
    public String toString() {
        String str;
        
        str = "** GSM MESSAGE **\n";
        str += "  Type: " + (type == TYPE_INCOMING ? "Incoming." : "Outgoing.") + "\n";
        str += "  Id: " + id + "\n";
        str += "  Memory Index: " + memIndex + "\n";
        str += "  Date: " + date + "\n";
        str += "  Originator: " + originator + "\n";
        str += "  Recipient: " + recipient + "\n";
        str += "  Text: " + text + "\n";
        str += "  Hex Text: " + KazaoGSMAlphabets.text2Hex(text, KazaoGSMAlphabets.GSM7BITDEFAULT) + "\n";
        str += "  Encoding: " + messageEncoding + "\n";
        str += "***\n";
        return str;
    }
    
    public boolean isFlash() {
        return flash;
    }
    
    public void setFlash(boolean flash) {
        this.flash = flash;
    }
    
    public boolean isReport() {
        return report;
    }
    
    public void setReport(boolean report) {
        this.report = report;
    }
}
